
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:syn_4s/core/extension/int_extension.dart';
import 'package:syn_4s/core/model/map_all_device_model.dart';
import 'package:syn_4s/ui/shared/app_theme.dart';
import 'package:syn_4s/ui/widgets/google_map_item.dart';
import 'package:syn_4s/ui/widgets/shadow_container.dart';

import 'dialog_title.dart';

class GoogleMapWatchDialog extends StatelessWidget {

  final String title;
  final borderStyle = BorderSide(width: 2.px, color: Colors.white);
  final MapAllDeviceModel? data;

  GoogleMapWatchDialog(this.title, this.data, {super.key});

  @override
  Widget build(BuildContext context) {
    return ShadowContainer(
      padding: EdgeInsets.all(8.px),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          DialogTitle(title, data!.statusName!),
          buildTopInfo(),
          buildWatchInfo(),
          GoogleMapItem(data)
        ],
      ),
    );
  }

  Widget buildTopInfo(){
    return Container(
      width: double.infinity,
      height: 80.px,
      margin: EdgeInsets.only(top: 10, left: 6.px, right: 6.px),
      child: Row(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                  border: Border(
                    left: borderStyle,
                    top: borderStyle,
                    bottom: borderStyle
                  )
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  setText("${data?.baseData?[0].val}", size: 28.px, color: AppTheme.redColor, fontWeight: FontWeight.w900),
                  setText("Heart Rate/bpm")
                ],
              ),
            )
          ),
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                  border: Border.all(width: 2.px, color: Colors.white)
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  setText("${data?.baseData?[1].val}", size: 28.px, fontWeight: FontWeight.w900),
                  setText("Body Temperature/℃")
                ],
              ),
            )
          )
        ],
      ),
    );
  }

  Widget buildWatchInfo(){
    return Container(
      margin: EdgeInsets.only(left: 6.px, right: 6.px, top: 10.px),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              setText("Wearer:${data!.staffName!}"),
              setText("IMEI:${data!.sn!}"),
            ],
          ),
          SizedBox(height: 10.px,),
          setText("Watch Type:${data!.deviceType!.name!}"),
          SizedBox(height: 10.px,),
          setText("Alert Type:${data!.alertType!.name!}"),
          SizedBox(height: 10.px,),
          Text("Address:${data!.address!}", style: TextStyle(fontSize: 14.px, color: AppTheme.textColor))
        ],
      ),
    );
  }

  Widget setText(String text,{double? size, FontWeight? fontWeight, Color color = AppTheme.textColor}){
    return Text(
      text,
      style: TextStyle(
          fontSize: size ?? 14.px,
          fontWeight: fontWeight,
          color: color
      ),
      overflow: TextOverflow.ellipsis,
      maxLines: 1,
    );
  }

}
